package archer.application.core.api.internal.system;

import archer.application.core.entity.system.Role;
import archer.application.core.service.system.RoleService;
import archer.application.core.api.BaseController;
import archer.framework.protocol.result.ExecuteResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author christ
 * @date 2016/6/7
 */
@RestController
@RequestMapping("/api/v*/internal/system/role")
@Transactional
public class RoleApi extends BaseController {

    @Autowired
    RoleService roleService;

    @RequestMapping("store")
    public ExecuteResult store(Role role) {

        return roleService.store(role);
    }

    @RequestMapping("delete")
    public ExecuteResult delete(String id) {

        return roleService.delete(id);
    }

    @RequestMapping("deleteAll")
    public ExecuteResult deleteAll(String ids) {

        return roleService.deleteAll(split(ids));
    }

    @RequestMapping("find")
    public ExecuteResult find() {

        return success();
    }

    @RequestMapping("find/{id}")
    public ExecuteResult find(@PathVariable String id) {

        return roleService.find(id);
    }

    @RequestMapping("findPagedList")
    public ExecuteResult findPagedList(String queryCondition) {

        return roleService.findPagedList(asCondition(queryCondition));
    }

    @RequestMapping("findSelectedStaffPagedList")
    public ExecuteResult findSelectedStaffPagedList() {

        return success(emptyList());
    }

    @RequestMapping("findSelectedStaffPagedList/{id}")
    public ExecuteResult findSelectedStaffPagedList(@PathVariable String id, String queryCondition) {

        return roleService.findSelectedStaffPagedList(id, asCondition(queryCondition));
    }

    @RequestMapping("findUnselectedStaffPagedList")
    public ExecuteResult findUnselectedStaffPagedList() {

        return success(emptyList());
    }

    @RequestMapping("findUnselectedStaffPagedList/{id}")
    public ExecuteResult findUnselectedStaffPagedList(@PathVariable String id, String queryCondition) {

        return roleService.findUnselectedStaffPagedList(id, asCondition(queryCondition));
    }

    @RequestMapping("assignUsers/{id}")
    public ExecuteResult assignUsers(@PathVariable String id, String userIds) {

        return roleService.assignUsers(id, split(userIds));
    }

    @RequestMapping("unAssignUsers/{id}")
    public ExecuteResult unAssignUsers(@PathVariable String id, String userIds) {

        return roleService.unAssignUsers(id, split(userIds));
    }

    @RequestMapping("findSelectedMenus")
    public ExecuteResult findSelectedMenus() {

        return success(emptyList());
    }

    @RequestMapping("findSelectedMenus/{id}")
    public ExecuteResult findSelectedMenus(@PathVariable String id) {

        return roleService.findSelectedMenus(id);
    }

    @RequestMapping("assignMenus/{id}")
    public ExecuteResult assignMenus(@PathVariable String id, String menuIds) {

        return roleService.assignMenus(id, split(menuIds));
    }
}
